/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package koalaui.arkoala

import koalaui.interop.*

// add inheritance from NativePeerNode
public open class PeerNode(peerPtr: pointer, val id: Int, val name: String, flags: Int) {
    public var peer: NativePeerNode

    init {
        peer = NativePeerNode.create(peerPtr)
    }

    companion object {
        protected var currentId: Int = 1000
        private var PEER_NODE_TYPE: UInt = 11u

        fun nextId(): Int {
            this.currentId += 1
            return currentId
        }

        fun generateRootPeer(): PeerNode {
            // just stub for now to make application work
            val peerPtr = InteropNativeModule._Malloc(4)
            val peerId = PeerNode.nextId()
            val root = PeerNode(peerPtr, peerId, "Root", 0)
            root.peer.finalizer = InteropNativeModule._GetMallocFinalizer()
            return root
        }
    }
    
    fun applyAttributes(attrs: HashMap<String, Any>) {}
}